<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="考核日期" prop="zrsKhdate">
        <!--<el-date-picker clearable
          v-model="queryParams.zrsKhdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择考核日期">
        </el-date-picker> -->
        <el-date-picker
              v-model="queryParams.zrsKhdate"
              type="month"
              value-format="yyyy-MM"
              placeholder="选择月">
            </el-date-picker>
      </el-form-item>
      <el-form-item label="考核部门" prop="zrsKhdeptCode">
        <el-input
          v-model="queryParams.zrsKhdeptCode"
          placeholder="请输入考核部门code或者考核部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_zrs_df_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-folder-checked"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:zbmanage:add']"
        >责任书汇算</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ZrsDfMainList" @selection-change="handleSelectionChange">
      <el-table-column label="责任书编码" align="center" prop="zrsMainId" />
      <el-table-column label="考核日期" align="center" prop="zrsKhdate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zrsKhdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="科室CODE" align="left" prop="zrsKhdeptCode" />
      <el-table-column label="考核部门名称" align="left" prop="zrsKhdeptName" />
      <el-table-column label="责任书名称" align="left" prop="zrsName" />
      <el-table-column label="责任书简称" align="left" prop="zrsJname" :show-overflow-tooltip="true"/>
      <el-table-column label="打分状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_zrs_df_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="分数" align="center" prop="countFs" >
        <template slot-scope="scope">
          <span v-if="scope.row.countFs">{{scope.row.countFs}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="附件数量" align="center" prop="countAnnex" >
        <template slot-scope="scope">
          <span v-if="scope.row.countFs">{{scope.row.countAnnex}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleView(scope.row)"
            v-hasPermi="['business:ZrsDfMain:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="scope.row.status == '0'"
            v-hasPermi="['business:ZrsDfMain:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改责任书模版管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="汇算日期" prop="zrsKhdateStr">
          <el-date-picker
                v-model="form.zrsKhdateStr"
                type="month"
                value-format="yyyy-MM"
                placeholder="选择月">
              </el-date-picker>
        </el-form-item>
        <div style="color: red;font-size: 18px;padding-top: 30px;">注意事项：已经打分完成的不需要从新汇算！</div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="settleSubmitForm">汇 算</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listZrsDfMainDept, getZrsDfMain, delZrsDfMain, addZrsDfMain, updateZrsDfMain,
settleZrsDf,
} from "@/api/business/ZrsDfMain";

export default {
  name: "ZrsDfMainDept",
  dicts: ['sys_zrs_df_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 责任书打分表格数据
      ZrsDfMainList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zrsMbId: null,
        zrsName: null,
        zrsJname: null,
        deptId: null,
        zrsKhdeptCode: null,
        zrsKhdeptName: null,
        userId: null,
        zrsKhuserName: null,
        zrsKhdate: null,
        status: null,
        mbType: "1",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        zrsKhdateStr: [
          { required: true, message: "汇算日期不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询责任书打分列表 */
    getList() {
      this.loading = true;
      listZrsDfMainDept(this.queryParams).then(response => {
        this.ZrsDfMainList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    reset() {
      this.form = {
        zrsKhdate: null
      };
      this.resetForm("form");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.zrsMainId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 汇算按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "责任书汇算";
    },
    handleView(row){
      let zrsMainId = row.zrsMainId;
      const params = { pageNum: this.queryParams.pageNum };
      this.$tab.openPage("责任书[" + row.zrsJname + "_"+row.zrsKhdate+"]查看", '/zrsDf/df-view/index/' + zrsMainId, params);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const zrsMainId = row.zrsMainId || this.ids
      getZrsDfMain(zrsMainId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改责任书打分";
      });
    },
    /** 提交按钮 */
    settleSubmitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.mbType = '1';
          settleZrsDf(this.form).then(response => {
            this.$modal.msgSuccess("汇算成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const zrsMainIds = row.zrsMainId || this.ids;
      this.$modal.confirm('是否确认删除责任书打分编号为"' + zrsMainIds + '"的数据项？').then(function() {
        return delZrsDfMain(zrsMainIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
